﻿$(function () {
    var columns = [{ "data": "GetNO" }, { "data": "Type" }, { "data": "In" }, { "data": "Name" }, { "data": "Rest" }, { "data": "Title" }, { "data": "Remarks" }, { "data": "AddDT" }]
    dataTable("/Finance/GetOrderJournal", columns, false)
    $("#dataTable_wrapper .row:last-child").addClass("mt-2");
    $("#exampleAccordion>li:nth-child(2)").addClass("active");
})

var dataTable =  function (url, columns, search, sSearchPlaceholder) {
        $('#dataTable').dataTable({
            "sScrollX": "100%",
            "bScrollCollapse": true,
            "serverSide": true,
            "processing": true,
            "bFilter": search,
            "ordering": false,
            "stateSave": false,
            "deferRender": true,
            "stateDuration": 60 * 60 * 24,
            "pagingType": "simple_numbers",  //分页样式：simple,simple_numbers,full,full_numbers
            ajax: function (data, callback, settings) {
                //封装请求参数
                var param = {};
                param.size = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                //param.start = data.start;//开始的记录序号
                param.index = (data.start / data.length) + 1;//当前页码
                param.key = data.search.value;
                param.no = $("#No").val();
                //console.log(data);
                $.ajax({
                    type: "POST",
                    url: url,//
                    cache: false,  //禁用缓存
                    data: param,  //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        //setTimeout仅为测试延迟效果
                        //封装返回数据
                        var returnData = {};
                        returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                        returnData.recordsTotal = result.total;//返回数据全部记录
                        returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                        returnData.data = result.Data;//返回的数据列表
                        //console.log(returnData);
                        //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                        //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
                        callback(returnData);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg("请求服务器出错")
                    }
                });
            },
            //列表表头字段
            columns: columns,
            "oLanguage": { //国际化配置  
                "sProcessing": "正在获取数据，请稍后...",
                "sLengthMenu": "显示 _MENU_ 条",
                "sZeroRecords": "没有您要的内容",
                "sSearchPlaceholder": sSearchPlaceholder,
                "sInfo": "从 _START_ 到  _END_ 条 总共 _TOTAL_ 条",
                "sInfoEmpty": "记录数为0",
                "sInfoFiltered": "(全部记录数 _MAX_ 条)",
                "sInfoPostFix": "",
                "sSearch": "搜索",
                "sUrl": "",
                "oPaginate": {
                    "sFirst": "第一页",
                    "sPrevious": "上一页",
                    "sNext": "下一页",
                    "sLast": "最后一页"
                }
            },
        }).api();
    }